package com.xinyun.server.protocol;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;

/**
 * Created by bubusy on 16/5/22.
 */
public class ProtocolData {

    protected ProtocolDataHeader header;
    protected ByteBuf bodyBytes;

    public ProtocolData() {
        this.header = new ProtocolDataHeader();
        this.bodyBytes = Unpooled.buffer();
    }

    public ProtocolData(ProtocolDataHeader header, ByteBuf bodyBytes) {
        this.header = header;
        this.bodyBytes = bodyBytes;
    }

    public ProtocolDataHeader getHeader() {
        return this.header;
    }


    @Override
    public String toString() {
        String str = header.toString();
        ByteBuf bytes = bodyBytes.copy();
        while (bytes.isReadable()) {
            str += bytes.readUnsignedByte() + " ";
        }
        return str;
    }

    public ByteBuf getBodyBytes() {
        return bodyBytes;
    }
}
